Ext.onReady(function() {
			var canNew = true;
			var addBybp = {
				text : '添加',
				xtype : 'button',
				listeners : {
					click : function() {
						location.href = "/wuziMgr/add_bybp";
					}
				}
			};
			var deleteBybp = {
				text : '删除',
				xtype : 'button',
				listeners : {
					click : function() {
						var grid = Ext.getCmp("spareparts_grid");
						var selectionModel = grid.getSelectionModel();
						var models = selectionModel.getSelection();
						var ids = [];
						for (var i = 0; i < models.length; i++) {
							ids[i] = models[i].get("Id");
						}
						Ext.Ajax.request({
									url : '/spareparts/delete',
									type : 'POST',
									params : {
										ids : ids
									},
									callback : function(options, success,
											response) {
										if (success) {
											var result = Ext
													.decode(response.responseText);
											if (result.success) {
												Ext.getCmp("spareparts_grid")
														.getStore().reload();
											}
										}
									}
								});
					}
				}
			};
			var refreshBybp = {
				text : '刷新',
				xtype : 'button',
				listeners : {
					click : function() {
						Ext.getCmp("spareparts_grid").getStore().reload();
					}
				}
			};
			
			var exportExcel = {
					text : '导出清单',
					xtype : 'button',
					listeners : {
						click : function() {
							window.open('/spareparts/exportAll');
						}
					}
				};
			
			var toolbar = Ext.create('Ext.toolbar.Toolbar', {
						dock : 'top',
						items : []
					});
			Ext.Ajax.request({
						url : 'privilege/has_privilege',
						params : {
							action : '/spareparts/add'
						},
						callback : function(options, success, response) {
							if (success) {
								try {
									var ar = Ext.decode(response.responseText);
									canNew = ar.data;
								} catch (e) {
									canNew = false;
								}
							} else {
								canNew = false;
							}
							if (canNew) {
								toolbar.add(addBybp);
								toolbar.add(deleteBybp);
							}
							toolbar.add(refreshBybp);
							toolbar.add(exportExcel);
						}
					});
			var store = Ext.create('Ext.data.Store', {
						fields : ['Id', {
									name : "Group",
									type : "object"

								}, {
									name : "DeviceType",
									type : "object"
								}, "Count", "MinInventory"],
						autoLoad : true,
						pageSize: 25,
						proxy : {
							type : 'ajax',
							url : '/spareparts/all',
							reader : {
								type : 'json',
								root : 'data.rows',
								totalProperty: 'data.total'
							}
						}
					});
			var grid = Ext.create('Ext.grid.Panel', {
						id : "spareparts_grid",
						selType : 'checkboxmodel',
						store : store,
						margin : '5 5',
						columns : [{
									text : '序号',
									xtype : 'rownumberer',
									width : 40,
									sortable : false
								}, {
									text : '备品名称',
									dataIndex : 'DeviceType',
									renderer : function(v) {
										return v.Name;
									}
								}, {
									text : '班组',
									dataIndex : 'Group',
									renderer : function(v) {
										return v.Name;
									}
								}, {
									text : '数量',
									dataIndex : 'Count'
								}, {
									text : '最小库存',
									dataIndex : 'MinInventory',
									flex : 1
								}, {
									text : '详细',
									renderer : function(v, meta, record) {
										return '<a href="spareparts/detail/'
												+ record.get("Id") + '">详细</a>';
									}
								}],
								bbar : Ext.create('Ext.PagingToolbar', {
									store : store,
									border: false,
									displayInfo : true,
									displayMsg : '显示{0} - {1} / 总数 {2}',
									emptyMsg : "没数据"
								})
					});

			var panel = Ext.create("Ext.panel.Panel", {
						title : '',
						border : false,
						bodyBorder : false,
						layout : 'fit',
						dockedItems : [toolbar],
						items : [grid]
					});
			Ext.create('Ext.Viewport', {
						layout : 'fit',
						style : 'background:none;background-color:white;',
						items : [panel]
					});
		});